home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2410 / 2410.xpi / chrome / content / review.xml < prev   
Extensible Markup Language  |  2010-01-28  |  11KB  |  276 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE dialog SYSTEM "chrome://foxmarks/locale/foxmarks.dtd">
  3. <bindings xmlns="http://www.mozilla.org/xbl"
  4.     xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  5.     xmlns:xbl="http://www.mozilla.org/xbl">
  6.     <binding id="xmarks-review-stars">
  7.         <!-- content, property, method and event descriptions go here -->
  8.         <content>
  9.             <xul:vbox style="margin: 0 5px" >
  10.                 <xul:image 
  11.                     src="chrome://foxmarks/skin/images/rating_0_stars.png"
  12.                     width="75" height="15" style="cursor: pointer" />
  13.                 <xul:spacer flex="1" />
  14.             </xul:vbox>
  15.         </content>
  16.         <handlers>
  17.             <handler event="mouseup" button="0">
  18.                 <![CDATA[
  19.                 this.rating = this.starIndex(event);
  20.                 ]]>
  21.             </handler>
  22.             <handler event="mouseover">
  23.                 <![CDATA[
  24.                 this.stars = this.starIndex(event);
  25.                 ]]>
  26.             </handler>
  27.             <handler event="mousemove">
  28.                 <![CDATA[
  29.                 this.stars = this.starIndex(event);
  30.                 ]]>
  31.             </handler>
  32.             <handler event="mouseout">
  33.                 <![CDATA[
  34.                 this.stars = this.rating;
  35.                 ]]>
  36.             </handler>
  37.         </handlers>
  38.         <implementation>
  39.             <constructor>
  40.                 if (this.hasAttribute('rating')) {
  41.                     this.rating = this.getAttribute('rating');
  42.                 }
  43.             </constructor>
  44.             <method name="starIndex">
  45.                 <parameter name="event" />
  46.                 <body>
  47.                     return Math.floor((event.clientX - this.boxObject.x - 5) / 
  48.                         15) + 1;
  49.                 </body>
  50.             </method>
  51.             <property name="rating">
  52.                 <getter>
  53.                     return this.getAttribute('rating');
  54.                 </getter>
  55.                 <setter>
  56.                     <![CDATA[
  57.                     var v = Number(String(val), 10);
  58.                         if (isNaN(v) || v < 0 || v > 5) {
  59.                         return this.getAttribute('rating');
  60.                     }
  61.                     this.setAttribute('rating', ''+v);
  62.                     this.stars = v;
  63.                     return ''+v;
  64.                     ]]>
  65.                 </setter>
  66.             </property>
  67.             <property name="stars">
  68.                 <getter>
  69.                     return this.getAttribute('stars');
  70.                 </getter>
  71.                 <setter>
  72.                     <![CDATA[
  73.                     var v = Number(val);
  74.                     if (isNaN(v) || v < 0 || v > 5) {
  75.                         return this.stars;
  76.                     }
  77.                     v = Math.round(v * 2) / 2.0;
  78.                     if (this.stars != v) {
  79.                         this.setAttribute('stars', ''+v);
  80.                         var img = document.getAnonymousNodes(this)[0].
  81.                             childNodes[0];
  82.                         img.src = "chrome://foxmarks/skin/images/rating_" + 
  83.                             String(v) + "_stars.png";
  84.                     }
  85.                     return ''+v;
  86.                     ]]>
  87.                 </setter>
  88.             </property>
  89.         </implementation>
  90.     </binding>
  91.  
  92.     <binding id="xmarks-review-status">
  93.         <content>
  94.             <xul:hbox >
  95.                 <xul:label style="margin: 2px 0 0 6px; padding: 0;" />
  96.                 <xul:label class="text-link xmarks-review-link" 
  97.                     style="margin: 2px 0 0; padding: 0; 
  98.                         cursor: pointer !important;" 
  99.                     xbl:inherits="href" href="http://www.xmarks.com/" />
  100.                 <xul:label style="margin: 2px 0 0; padding: 0;" />
  101.                 <xul:spacer flex="100" />
  102.             </xul:hbox>
  103.         </content>
  104.         <implementation>
  105.             <constructor>
  106.                 <![CDATA[
  107.                 if (this.hasAttribute('iRated') && 
  108.                         this.getAttribute('iRated') != 'true') {
  109.                     this.iRated = false;
  110.                 }
  111.                 if (!this.hasAttribute('numRatings')) {
  112.                     this.numRatings = 0;
  113.                 }
  114.                 this.updateText();
  115.                 ]]>
  116.             </constructor>
  117.             <method name="updateText">
  118.                 <body>
  119.                     <![CDATA[
  120.                     var n = Xmarks.Bundle().GetStringFromName;
  121.                     var f = Xmarks.Bundle().formatStringFromName;
  122.  
  123.                     var str = "";
  124.  
  125.                     if (this.numRatings > 0 && !this.iRated) {
  126.                         str = f("reviews.otherrating", [this.numRatings], 1);
  127.                     } else if (this.numRatings <= 1 && this.iRated) {
  128.                         str = n("reviews.yourrating");
  129.                     } else if (this.numRatings > 1 && this.iRated) {
  130.                         str = f("reviews.bothrating", [this.numRatings], 1);
  131.                     } else {
  132.                         str = n("reviews.notyetrated");
  133.                     }
  134.                     var strs = str.split("|");
  135.                     strs.push("");
  136.                     strs.push("");
  137.                     var box = document.getAnonymousNodes(this)[0];
  138.                     box.childNodes[0].value = strs[0];
  139.                     box.childNodes[1].value = strs[1];
  140.                     box.childNodes[2].value = strs[2];
  141.                     ]]>
  142.                 </body>
  143.             </method>
  144.             <property name="numRatings" 
  145.                 onget="return Number(this.getAttribute('numRatings'));">
  146.                 <setter>
  147.                     <![CDATA[
  148.                     var v = Math.floor(Number(val));
  149.                     if (isNaN(v) || v < 0) {
  150.                         return this.numRatings;
  151.                     }
  152.                     this.setAttribute('numRatings', ''+v);
  153.                     this.updateText();
  154.                     return v;
  155.                     ]]>
  156.                 </setter>
  157.             </property>
  158.             <property name="iRated"
  159.                 onget="return this.hasAttribute('iRated');">
  160.                 <setter>
  161.                     <![CDATA[
  162.                     var v = val && val != 'false';
  163.                     if (v) {
  164.                         this.setAttribute('iRated', 'true');
  165.                     } else {
  166.                         this.removeAttribute('iRated');
  167.                     }
  168.                     this.updateText();
  169.                     return v;
  170.                     ]]>
  171.                 </setter>
  172.             </property>
  173.             <property name="url">
  174.                 <setter>
  175.                     <![CDATA[
  176.                     var url = val;
  177.                     var label = document.getAnonymousNodes(this)[0].
  178.                         childNodes[1];
  179.                     url = url.replace(/^http:\/\//i, "");
  180.                     var href = Xmarks.gSettings.httpProtocol + 
  181.                         Xmarks.gSettings.driftHost + "/site?url=" + 
  182.                         encodeURIComponent(url) + "&cid=xmfx.bd.review" + 
  183.                         "&product=xmarks&anchor=r";
  184.                     label.href = href;
  185.                     ]]>
  186.                 </setter>
  187.             </property>
  188.         </implementation>
  189.     </binding>
  190.  
  191.     <binding id="xmarks-review">
  192.         <content>
  193.             <xul:vbox flex="1">
  194.                 <xul:hbox>
  195.                     <xul:xmarks-review-stars xbl:inherits="rating"
  196.                         onclick="document.getBindingParent(this).clicked();"/>
  197.                     <xul:xmarks-review-status 
  198.                         xbl:inherits="iRated,numRatings,href"/>
  199.                 </xul:hbox>
  200.                 <xul:textbox collapsed="true" multiline="true" rows="3"
  201.                     xbl:inherits="value=reviewText" 
  202.                     class="menulist-editable-box"
  203.                     emptytext= "&reviews.emptytext;"
  204.                     oninput="document.getBindingParent(this).changed = true" />
  205.             </xul:vbox>
  206.         </content>
  207.         <implementation>
  208.             <constructor>
  209.             </constructor>
  210.             <field name="url" />
  211.             <field name="url_id" />
  212.             <property name="status">
  213.                 <getter>
  214.                     var ann = document.getAnonymousNodes(this)[0];
  215.                     return ann.childNodes[0].childNodes[1];
  216.                 </getter>
  217.             </property>
  218.             <property name="textbox">
  219.                 <getter>
  220.                     var ann = document.getAnonymousNodes(this)[0];
  221.                     return ann.childNodes[1];
  222.                 </getter>
  223.             </property>
  224.             <property name="stars">
  225.                 <getter>
  226.                     var ann = document.getAnonymousNodes(this)[0];
  227.                     return ann.childNodes[0].childNodes[0];
  228.                 </getter>
  229.             </property>
  230.             <property name="changed">
  231.                 <getter>return this.hasAttribute("changed");</getter>
  232.                 <setter>
  233.                     if (val) {
  234.                         this.setAttribute("changed", "true");
  235.                     } else {
  236.                         this.removeAttribute("changed");
  237.                     }
  238.                 </setter>
  239.             </property>
  240.  
  241.             <method name="clicked">
  242.                 <body>
  243.                     this.status.iRated = true;
  244.                     this.textbox.collapsed = false;
  245.                     this.changed = true;
  246.                 </body>
  247.             </method>
  248.             <method name="initialize">
  249.                 <parameter name="url" />
  250.                 <parameter name="url_id" />
  251.                 <parameter name="count" />
  252.                 <parameter name="average" />
  253.                 <parameter name="rating" />
  254.                 <parameter name="review" />
  255.                 <body>
  256.                     <![CDATA[
  257.                     this.status.numRatings = count || 0;
  258.                     this.status.iRated = rating != null;
  259.                     this.status.url = url;
  260.                     this.stars.rating = rating || average || 0;
  261.                     this.textbox.value = review || "";
  262.                     this.textbox.collapsed =  !rating;
  263.                     this.changed = false;
  264.                     this.url = url;
  265.                     this.url_id = url_id;
  266.                     if (this.status.iRated && this.status.numRatings > 0) {
  267.                         this.status.numRatings -= 1;
  268.                     }
  269.                     ]]>
  270.                 </body>
  271.             </method>
  272.         </implementation>
  273.     </binding>
  274. </bindings>
  275.  
  276.